package com.example.administrator.foodrowfresh.jiao.modle;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/4.
 */
public class PromotionItemModel {


    /**
     * success : 1
     * data : {"title":"粽享滋味","content":"","IsTimeOver":"0","begin_time":"1461200472","image":"http://images4sh-app.34580.com/images/ProductImages/SH_Image_19808_jpeg_640.jpeg"}
     */

    private int success;
    /**
     * title : 粽享滋味
     * content :
     * IsTimeOver : 0
     * begin_time : 1461200472
     * image : http://images4sh-app.34580.com/images/ProductImages/SH_Image_19808_jpeg_640.jpeg
     */

    private DataBean data;

    public static PromotionItemModel objectFromData(String str) {

        return new Gson().fromJson(str, PromotionItemModel.class);
    }

    public static PromotionItemModel objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getString(str), PromotionItemModel.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<PromotionItemModel> arrayPromotionItemModelFromData(String str) {

        Type listType = new TypeToken<ArrayList<PromotionItemModel>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<PromotionItemModel> arrayPromotionItemModelFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<PromotionItemModel>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getString(str), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }

    public int getSuccess() {
        return success;
    }

    public void setSuccess(int success) {
        this.success = success;
    }

    public DataBean getData() {
        return data;
    }

    public void setData(DataBean data) {
        this.data = data;
    }

    public static class DataBean {
        private String title;
        private String content;
        private String IsTimeOver;
        private String begin_time;
        private String image;

        public static DataBean objectFromData(String str) {

            return new Gson().fromJson(str, DataBean.class);
        }

        public static DataBean objectFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);

                return new Gson().fromJson(jsonObject.getString(str), DataBean.class);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        public static List<DataBean> arrayDataBeanFromData(String str) {

            Type listType = new TypeToken<ArrayList<DataBean>>() {
            }.getType();

            return new Gson().fromJson(str, listType);
        }

        public static List<DataBean> arrayDataBeanFromData(String str, String key) {

            try {
                JSONObject jsonObject = new JSONObject(str);
                Type listType = new TypeToken<ArrayList<DataBean>>() {
                }.getType();

                return new Gson().fromJson(jsonObject.getString(str), listType);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return new ArrayList();


        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getIsTimeOver() {
            return IsTimeOver;
        }

        public void setIsTimeOver(String IsTimeOver) {
            this.IsTimeOver = IsTimeOver;
        }

        public String getBegin_time() {
            return begin_time;
        }

        public void setBegin_time(String begin_time) {
            this.begin_time = begin_time;
        }

        public String getImage() {
            return image;
        }

        public void setImage(String image) {
            this.image = image;
        }
    }
}
